
<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
 session_start();
if($_SESSION['username']!=null)
{
 
$title="Thêm danh muc bài viết";


require '../layout/headeradmin.inc';

$title="";
$cate_id=0;
$images="";
$introtext="";
$fulltext="";
$chk=0;
$metakey="";
$create_by=1;
$modified_by=1;

if(isset($_POST['them_bv']))
{
    
   $title=  trim($_POST['title']);
   $cate_id=trim($_POST['cate_id']);
        
  
   $introtext=  trim(addslashes($_POST['introtext']));
    $fulltext= trim( addslashes($_POST['fulltext']));;
    echo stripslashes($fulltext);
    if(isset($_POST['chk']))
          $chk=1;
    
   
    $metakey= trim(addslashes($_POST['metakey']));
    $create_by=1;
    $modified_by=1;
    
    
    
    
    
if($_FILES['file']['error']>0)
{
//    echo 'Error:'.$_FILES['file']['error'];
}
 else {
    if(file_exists('../upload/'.$_FILES['file']['name']))
            unlink('../upload/'.$_FILES["file"]["name"]);

     $images=$_FILES['file']['name']; 
     move_uploaded_file($_FILES["file"]["tmp_name"],
      "../uploadimages/" . $_FILES["file"]["name"]);
  
 }
     if(get_magic_quotes_gpc())
    {
        $title=  trim(addslashes($_POST['title']));
        $cate_id=trim(addslashes($_POST['cate_id']));

      
        $introtext=  trim(addslashes($_POST['introtext']));
        $fulltext=trim(addslashes($_POST['fulltext']));;
        if(isset($_POST['chk']))
             $chk=1;

       
        $metakey= trim(mysqli_real_escape_string($_POST['metakey']));
   
    }
   //  $k->insertArticle($title,$introtext,$fulltext,$cate_id,$create_by,$modified_by,$chk,$images,$metakey);
   //  
   //  
    
    $db=  mysqli_connect("localhost", "root", "", "datashop");
 $create=date("Y-m-d");
  $modified=date("Y-m-d");
           $sql = "INSERT INTO `content`(`title` , `introtext` , `fulltext` , `catid` , `created` , `created_by` , `modified` , `modified_by` , `publish_up` , `images` , `metakey` )"
                               ." VALUES ('$title','$introtext','$fulltext','$cate_id','$create','$create_by','$modified','$modified_by','$chk','$images','$metakey')";
        mysqli_query($db, $sql) or die(mysqli_error($db)) ;
        
  //  header("Location:home.php");
}
 else {
    

?>
<!--<script src="../plugin/ckeditor_4.4.4_full/ckeditor/ckeditor.js" type="text/javascript"></script>-->
<script src="../plugin/tinymce/tinymce.min.js" type="text/javascript"></script>
<script type="text/javascript">
tinymce.init({
    selector: "textarea#fulltext",
    language : 'vi_VN',
    theme: "modern",
    
//    width: 300,
//    height: 300,
    skin : 'lightgray',
    paste_data_images: true,  /* dán ảnh vào editor*/
     force_br_newlines : true,
        force_p_newlines : false,
        forced_root_block : '',
theme_advanced_buttons2 : "ibrowser",



    plugins: [
         "advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
         "searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
         "save table contextmenu directionality emoticons template paste textcolor "
   ],
   content_css: "css/content.css",
   toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | l      ink image | print preview media fullpage | forecolor backcolor emoticons", 
   style_formats: [
        {title: 'Bold text', inline: 'b'},
        {title: 'Red text', inline: 'span', styles: {color: '#ff0000'}},
        {title: 'Red header', block: 'h1', styles: {color: '#ff0000'}},
        {title: 'Example 1', inline: 'span', classes: 'example1'},
        {title: 'Example 2', inline: 'span', classes: 'example2'},
        {title: 'Table styles'},
        {title: 'Table row 1', selector: 'tr', classes: 'tablerow1'}
    ]

            
 });
</script>
<?php
//echo $_SERVER['DOCUMENT_ROOT'];
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data">
    <fieldset>
        <legend><text>Bài viết</text></legend>
        <table id="t-adduser">
            <tbody>
                <tr>
                    <td><label>Tiêu đề</label></td>
                    <td><input type="text" id="title" name="title"></td>
                </tr>
                <tr>
                    <td><label>Metakey</label></td>
                    <td><input type="text" id="metakey" name="metakey"></td>
                </tr>
<!--                 <tr>
                    <td><label>ckeditor</label></td>
                    <td><textarea row="4" cols="100" class="ckeditor" name="eddd" ></textarea></td>
                </tr>-->
                <tr>
                    <td><label>Danh mục</label></td>
                    <td>
                        
                        <?php 
//                        echo mysqli_num_rows($k->getCateParent());
//                        if(mysqli_num_rows($k->getCateParent())>0)
//                        {
//   
                            ?>
                            <select id="se" name="cate_id">
                           
                                <?php 
                                
                                    $data=$k->getCateParent();
                                    echo mysqli_num_rows($data);
                                   while ($row = mysqli_fetch_array($data)) {
                                        
                                 
                                
                                
                                ?>
                                <option value="<?php echo $row['id'];?>"><?php echo $row['name_cate']; ?></option>
                          
                            
                        
                        <?php 
//                           }
                        }
// else {
//     
// }
                        ?>
                                </select>
                    </td>
                </tr>
                 <tr>
                    <td><label>Ảnh đại diện</label></td>
                    <td><input type="file" name="file" id="file"></td>
                </tr>
                 <tr>
                    <td><label>Thông tin</label></td>
                    <td><textarea row="4" cols="100"  id="introtext" name="introtext" ></textarea></td>
                </tr>
                <tr>
                    <td><label>Nội dung</label></td>
                     <td><textarea row="4" cols="100" class="ckeditor" name="fulltext" id="fulltext" ></textarea></td>
                </tr>
                <tr>
                    <td><label>Hiện</label></td>
                    <td><input type="checkbox" name="chk" id="chk"></td>
                </tr>
                <tr>
                    <td colspan="2" style="text-align: center;" >
                        <div>
                            <input type="submit" name="them_bv" value="Thêm" >
                            <input type="button" name="huy" value="Hủy" >
                        </div>
                    </td>
                </tr>
            </tbody>
            <tfoot>
                
            </tfoot>
        </table>
    </fieldset>
</form>



<?php
 }
require '../layout/footeradmin.inc';
}
else
{
	header('Location:index.php');
}
?>